<template>
  <el-dialog :title="'详情查看'" :visible.sync="dialogVisible" width="800px" fullscreen>
    <el-table :data="tableData" :loading="loadingTable" style="width: 100%;" max-height="660px">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column prop="applicationName" label="程序名称"></el-table-column>
      <el-table-column prop="boardType" label="板材类型"></el-table-column>
      <el-table-column prop="plateThickness" label="板材厚度"></el-table-column>
      <el-table-column prop="completionTime" label="完成时间" width="100"></el-table-column> >
      <el-table-column label="操作" width="180" fixed="right">
        <template slot-scope="scope">
          <div style="display: flex; justify-content: space-around">
            
            <el-button type="text" @click="getFilePreivewByUrl(scope.row.attachmentAddress)"><i class="el-icon-view"></i>预览pdf</el-button>
            
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getInfo } from './helper/api';
import { getToken } from "@/utils/auth"

export default {
  props: {
  },
  data() {
    return {
      loadingTable:false,
      dialogVisible: false,
      tableData: []
    };
  },
  methods: {
    showDialog(data) {
      this.dialogVisible = true;
      getInfo(data.layId).then(res => { 
       if(res.code==200){
        this.tableData = res.data;
       }
      });
    },
    getFilePreivewByUrl(url){
      console.log(url);
      fetch(url, {
            method: 'GET', // 默认就是GET，可省略
            headers: {
              Authorization: "Bearer " + getToken()
            }
          })
          .then(response => {
            // 检查请求是否成功
            if (!response.ok) {
              throw new Error(`HTTP error! status: ${response.status}`);
            }
            // 将响应转换为Blob对象（适 是二进制文件）
            return response.blob();
          })
          .then(blob => {
            // 创建PDF的URL
            const pdfUrl = URL.createObjectURL(blob);
            window.open(pdfUrl);
            console.log('pdfUrl', pdfUrl) //这个路径有问题
            
            // 这里可以使用这个URL进行PDF预览
            // 例如：设置iframe的src
            // document.getElementById('pdfViewer').src = pdfUrl;
            
            // 或者打开新窗口显示PDF
            this.pdfUrl=pdfUrl
          })
          .catch(error => {
            console.error('获取PDF失败:', error);
          });
    }
  }
};
</script>

<style scoped>
::v-deep .el-form-item.is-disabled .el-input__inner {
  background-color: #f5f7fa;
  border-color: #e4e7ed;
  color: #606266;
}
</style>